/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package game.platformer.levels;

import game.platformer.platformer;
import java.util.ArrayList;
import java.util.HashMap;

/**
 *
 * @author cow
 */
public class levelManager {
    //varblock-------------------------

    platformer game;
    Level currentLevel;
    //texture packages-----------------
    private grassTextureSet grasstex;
    private industryTextureSet industrytex;
    private iceTextureSet iceTex;
    private fireTextureSet fireTex;
    private elementsTextureSet elementsTex;
    //levels---------------------------
    private ArrayList<Level> levels;
    //---------------------------------
    //constructor

    public levelManager(platformer game) {
        this.game = game;

        //inisialize things
        levels = new ArrayList<Level>();
        grasstex = new grassTextureSet();
        industrytex = new industryTextureSet();
        currentLevel = null;
        iceTex = new iceTextureSet();
        fireTex = new fireTextureSet();
        elementsTex = new elementsTextureSet();

        //load up levels
        levels.add(new levelOne(game));
        levels.add(new levelTwo(game));
        levels.add(new levelThree(game));
        levels.add(new levelFour(game));
        levels.add(new levelFive(game));

        //load resources-----
        grasstex.loadTextures(game);
        industrytex.loadTextures(game);
        iceTex.loadTextures(game);
        fireTex.loadTextures(game);
        elementsTex.loadTextures(game);

		//load level resources
        for (Level l : levels) {
            l.loadTextures();
        }

    }
    //level manipulators-------------------------

    public int getNumLevels() {
        return levels.size(); //+1 cuz of index?  -- size returns the number of elements, not the max index --
    }

    /**
     * gets level number levelid
     * @param levelid
     * @return Level number (levelid)
     */
    public Level getLevel(int levelid) {
        try {
            return levels.get(levelid);
        } catch (IndexOutOfBoundsException e) {
            return levels.get(0);
        }
    }

    public void loadLevel(int levelid, int posX, int posY) {
        if (currentLevel != null) {
            currentLevel.unloadLevel();
        }
        currentLevel = levels.get(levelid);
		if(currentLevel != null){
			currentLevel.loadLevel(posX, posY);
		}
    }

    public void unloadLevel() {
        if (currentLevel == null) {
            return;
        }
        currentLevel.unloadLevel();
        currentLevel = null;
    }

    public Level getCurrentLevel() {
        return currentLevel;
    }
    //texture manipulators-----------------------

    public grassTextureSet getGrassTexSet() {
        return grasstex;
    }

    public industryTextureSet getIndustryTexSet() {
        return industrytex;
    }

    public iceTextureSet getIceMainPlatform() {
        return iceTex;
    }

    public fireTextureSet getFireMainPlatform() {
        return fireTex;
    }

    public elementsTextureSet getElementsMainPlatform() {
        return elementsTex;
    }
}
